<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //includes()判断数组中是否包含某个成员
        console.log([1, 2, 3].includes('2')); //false
        console.log([1, 2, 3].includes(2)); //true
        //第二个参数表示搜索的起始位置默认值是0
        console.log([1, 2, 3].includes(2, 1)); //true
        console.log([1, 2, 3].includes(2, 3)); //false
        //基本遵循严格相等（===）但是对于NaN的判断与===不同
        //includes认为NaN===NaN
        console.log(NaN === NaN); //false
        console.log([1, 2, NaN].includes(NaN)); //true


        //在实际中的应用
        //数组去重[1,2,3,1]
        const arr = [];
        for (const item of[1, 2, 3, 2, 1]) {
            if (!arr.includes(item)) {
                arr.push(item);
            }
        }
        console.log(arr) //[1,2,3]
    </script>

</body>

</html>